home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1993 / MacHack 1993.toast / MacHack™ 1987-1992 / MacHack™ '90 / Source Code ƒ / MPW C ƒ / Orphan ƒ / StripUnitsTool.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-09  |  2.2 KB  |  71 lines  |  [TEXT/MPS ]

  1. /*  Like the MPW 3.0 Tool to OrphanFiles, this strips 'unit' resources         */
  2. /*  This might work on 2.0.2 -- I haven't tried -- I don't see why it wouldn't */
  3.  
  4.  
  5. /* MPW C: (3.0 or later) */
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <resources.h>
  10. #include <cursorctl.h>
  11.  
  12. main(int argc, char *argv[])
  13. {
  14.     char i, j, k;
  15.     short resid, oldres;
  16.     Boolean progress;
  17.     Handle tempHandle;
  18.  
  19.     if (argc < 2) {
  20.         fprintf(stderr, "##  StripUnits [-p] file [files]\n");
  21.         return 1;
  22.     }
  23.     InitCursorCtl(nil);
  24.  
  25.     for (i = 1; i < argc; i++) {
  26.         SpinCursor(1);
  27.         if (!strcmp(argv[i], "-p")) {
  28.             progress = true;
  29.             for (j = i + 1; j < argc; j++)
  30.                 argv[j - 1] = argv[j];
  31.             argc--;
  32.             break;
  33.         } else
  34.             progress = false;
  35.     }
  36.     if (progress) {
  37.         printf("\StripUnits -- Very Fast Tool to replace Very Slow Script\n");
  38.         printf("February 3, 1990 by [Go For It]\n\n");
  39.     }
  40.     SetResLoad(false);
  41.     oldres = CurResFile();
  42.     for (i = 1; i < argc; i++) {
  43.         SpinCursor(1);
  44.         resid = openresfile(argv[i]);
  45.         if (ResError()) {
  46.             fprintf(stderr, "# File %s not found\n", argv[i]);
  47.             break;
  48.         }
  49.         if (j = CountResources('unit')) {
  50.             for (k = j; k >= 1; k--) {    /* Have to count backwards or we lose half of them */
  51.                 tempHandle = GetIndResource('unit', k);
  52.                 if (ResError() && progress)
  53.                     printf("# Could not access 'unit' resource index %d (error :%d) in file: %s\n"
  54.                            ,k, ResError(), argv[i]);
  55.                 RmveResource(tempHandle);
  56.                 if (progress) {
  57.                     if (ResError())
  58.                         printf("# Could not remove 'unit' resource index %d (error :%d) in file: %s\n"
  59.                                ,k, ResError(), argv[i]);
  60.                     else
  61.                         printf("# Removed 'unit' resource index %d in file: %s\n", k, argv[i]);
  62.                 }
  63.             }
  64.         } else if (progress)
  65.             printf("# %s has no 'unit' resource\n", argv[i]);
  66.  
  67.         CloseResFile(resid);
  68.     }
  69.     UseResFile(oldres);
  70. }
  71.